package com.hfs.fence

import android.os.Bundle
import android.util.Log
import com.amap.api.fence.GeoFence
import com.amap.api.fence.GeoFenceListener
import com.amap.api.location.AMapLocation

class NoMapActivity : BaseActivity() {

    private var locationUtil: LocationUtil? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //        定位回调
        setLocationCallBack()
    }


    private fun setLocationCallBack() {
        locationUtil = LocationUtil()
        //定位回调
        locationUtil!!.setLocationCallBack(object : LocationUtil.ILocationCallBack {
            override fun callBack(
                str: String?,
                lat: Double,
                lgt: Double,
                aMapLocation: AMapLocation?
            ) {
                //添加围栏也就是打卡范围  参数1上下文，添加结果回调 ，范围的直径也就是圆圈的直径 ，经纬度
                addCircleGeoFence(this@NoMapActivity, listener, 1000, lat, lgt)
            }
        })

        locationUtil!!.startLocate(applicationContext)
    }

    //判断围栏是否创建成功
    //添加围栏成功后注册广播监听进出围栏
    private val listener: GeoFenceListener
        get() = GeoFenceListener { list, errorCode, s ->
            if (errorCode == GeoFence.ADDGEOFENCE_SUCCESS) { //判断围栏是否创建成功
                Log.d(TAG, "添加围栏成功!!")
                //添加围栏成功后注册广播监听进出围栏
                registerReceiver()
            } else {
                Log.d(TAG, "添加围栏失败!!")
            }
        }


    override fun enter() {
    }

    override fun out() {
    }
}